<template>
	<div class="update_gender">
		<van-picker
		    show-toolbar
		    :columns="columns"
				:default-index="defaultIndex"
		    @cancel="$emit('close')"
		    @confirm="onConfirm"
				@change="onGenderChange"
		  />
	</div>
</template>

<script>
	import { updateUserProfile } from '../../../utils/user.js'
	export default {
		name:'updateGender',
		props:{
			value: {
				type:Number,
				required:true
			}
		},
		data() {
			return {
				 columns: ['男','女'],
				 defaultIndex:this.value
			}
		},
		methods:{
			onGenderChange(picker,value,index) {
				this.defaultIndex = index
			},
			async onConfirm() {
				this.$toast.loading({
					message:'保存中',
					forbidclick:true
				})
				
			  await updateUserProfile({
			   	gender: this.defaultIndex
			   })
			    
			   
			   this.$emit('input',this.defaultIndex)
			   
			   this.$emit('close')
				this.$toast.success('保存成功')
				
			}
		}
	}
</script>

<style scoped="scoped">
	
</style>
